<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ADD</title>
    <link rel="stylesheet" href="style/base.css">
    <script type="text/javascript" src="style/jquery.js"></script>
</head>
<body>

<!-- plugin.php?id=zhibo&ac=activity&op=post -->
<!--http://test.olbike.com:81/php/bikeshop/V2/?service=Live.Add-->
直播名称:<input type="text" name="channelName" id="channelName"/><br>
直播描述:<input type="text" name="channelDescribe" id="channelDescribe"/><br>
开始时间:<input type="text" name="start" id="start"/><br>
结束时间:<input type="text" name="end" id="end"/><br>
封面图片:<input type="text" name="logo" id="logo"/><br>
输出源名称:<input type="text" name="sourceName" id="sourceName"/><br>
<input type="hidden" name="sourceType" value='1' id="sourceType"/>
选择输出源:
<select name="outputSourceType" id="outputSourceType">
    <option value="3">RTMP/FLV HLS输出</option>
</select><br>
输出画质: <input type="checkbox" name="outputRate" value="0"/>原画
<input type="checkbox" name="outputRate" value="10"/>标清
<input type="checkbox" name="outputRate" value="20"/>高清<br>
显示水印:
<select name="watermarkId" id="watermarkId">
    <option value="1">显示水印</option>
    <option value="0">不显示水印</option>
</select><br>
<button id="add">提交</button>

<script>
    $(function () {
        $("#add").click(function () {
            obj = $("input[name='outputRate']");
            check_val = [];
            for (k in obj) {
                if (obj[k].checked)
                    check_val.push(obj[k].value);
            }
            $.ajax({
//                http://test.olbike.com:81/php/bikeshop/V2/?service=Live.Add
                url: 'http://test.olbike.com:81/php/bikeshop/V2/?service=Live.Add',
                type: 'post',
                dataType: 'json',
                data: {
                    "channelName": $("#channelName").val(),
                    "outputSourceType": $("#outputSourceType").val(),
                    "channelDescribe": $("#channelDescribe").val(),
                    "sourceName": $("#sourceName").val(),
                    "sourceType": $("#sourceType").val(),
                    "outputRate": check_val,
                },
                success: function (msg) {
                    console.log(check_val);
                    $.post('plugin.php?id=zhibo&ac=activity&op=post',{
                        "channelName" : $("#channelName").val(),
                        "start" : $("#start").val(),
                        "end" : $("#end").val(),
                        "logo" : $("#logo").val(),
                        "outputSourceType" : $("#outputSourceType").val(),
                        "outputRate" : check_val,
                        "watermarkId": $("#watermarkId").val(),
                        "channelId" : msg.data.channel_id,
                        "address" : msg.data.downstream_address[0],
                        "address2" : msg.data.downstream_address[1],
                    },function(data){
                        if(data){
                            alert('添加成功')
                        }
                    });
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert(textStatus);
                },
            });
        });
    });
</script>

</body>
</html>